package service

import (
	"github.com/pkg/errors"
	"nft-server/dao"
	"nft-server/model"
)

var (
	Categories = [...]string{
		"动漫",
		"艺术",
		"文物",
	}
)

func InitCategoryTable() error {
	// 如果存在就不插入
	for index := 0; index < len(Categories); index++ {
		realIndex := index + 1
		category, err := dao.GetCategoryDao().GetCategoryName(realIndex)
		if err != nil {
			continue
		}

		if category == nil {
			InsertCategory := &model.Category{
				Id:   realIndex,
				Name: Categories[index],
			}
			if err := dao.GetCategoryDao().InsertCategory(InsertCategory); err != nil {
				return errors.Errorf("InitRoleTable error: %v", err)
			}
		}

	}
	return nil
}
func GetCategoryNameById(categoryId int) string {
	if categoryId >=1  && categoryId <= len(Categories) {
		return Categories[categoryId - 1]
	} else {
		return ""
	}
}
